<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import {mRequest} from '@/utils/request'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        transactionType: {
          label: '往来类型',
          type: 'radio',
          radioBorder: true,
          radioList: [{text: '应收增加', label: '应收增加'}, {text: '应收减少', label: '应收减少'}],
          default: '应收减少'
        },
        dayTime: {
          label: '日期',
          type: 'date',
          placeholder: '请选择日期'
        },
        clientId: {
          type: 'list',
          list: [],
          label: '客户名',
          filterable: true,
          clearable: true,
          placeholder: '请输入客户'
        },
        discountTotalPrice: {
          label: '应收增加金额',
          type: 'number',
          placeholder: '请输入金额',
          max: 1000000000,
          reply: () => this.dataForm.transactionType=='应收增加',
        },
        receiveReduceAmount: {
          label: '应收减少金额',
          type: 'number',
          placeholder: '请输入金额',
          max: 1000000000,
          reply: () => this.dataForm.transactionType=='应收减少',
        },
        openingBalanceAmount:{
          label: '期初金额',
          type: 'number',
          placeholder: '请期初金额',
          max: 1000000000,
          min: -10000000
        },
        additionalRemark: {
          label: '附加说明',
          placeholder: '附加说明'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    addNewIngredient() {
      const cb = (newValue) => {
        this.initIngredientInfoList()
        this.dataForm.ingredientInfoId = newValue.id
      }
      this.$parent.openIngredientInfoDialog(cb)
    },
    ingredientIdSelectCallback() {
      //getSupplierListByIngredientId

      this.dataForm.supplierId = ''

      mRequest('supplierApi/getSupplierListByIngredientId', {id: this.dataForm.ingredientInfoId}, ({data}) => {
        this.dataFormConfig['supplierId'].list = this.R.propOr([], 'list', data)
      })

    },
    init(id) {
      this.dataForm.id = id || 0
      this.initClientInfoList('clientId')
      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('clientId', 'transactionType', 'dayTime'),
        initApi: 'financeApi/getFinanceTransactionProductInfo',
        saveApi: 'financeApi/saveFinanceTransactionProduct',
        updateApi: 'financeApi/updateFinanceTransactionProduct',
        objectName: 'financeTransactionProduct'
      })
    }
  }
}
</script>
